<template>
	<view class="order-manage full box relative bg-primary flex-col">
		<view class="header-wrap">
			<view class="header-search">
				<u-icon name="search" color="#8D8D8D" size="30rpx" />
				<input class="search-input" placeholder="请输入关键词" v-model="queryKey" />
			</view>
			<view class="search-btn" @click="handleSearch">
				<text>搜索</text>
			</view>
			<!-- <view class="filter-wrapper">
				<image mode="aspectFill" class="filter-icon" src="/static/images/filter_icon.png"></image>
				<text class="filter-text">筛选</text>
			</view> -->
		</view>
		<!-- <view class="tab-wrap">
			<u-tabs :list="tabList" :bar-style="{bottom:'-4px'}" :is-scroll="false" v-model="current"
				@change="handleTabChange" :bold="false"></u-tabs>
		</view> -->
		<view class="w-wrap">
			<view class="w-inner">
				<mescroll-uni @init="mescrollInit" :fixed="false" @down="downCallback" @up="upCallback">
					<view class="record-list">
						<view class="record-item" v-for="(item,index) in list" :key="index" @click="handleToDetail(item)">
							<view class="record-header">
								<text class="order-no">{{ item.sn }}</text>
								<text class="order-status">{{ item.status_text }}</text>
							</view>
							<view class="order-type">
								<text>备货单</text>
							</view>
							<view class="desc-item active">
								<text>联系人：{{ item.address?.name }}</text>
								<text>创建时间：{{ item.create_time }}</text>
							</view>
							<view class="desc-item">
								<text>联系电话：{{ item.address?.mobile }}</text>
							</view>
							<view class="desc-item">
								<text>安装地址：{{ item.address?.shouhuo_address }}</text>
							</view>
							<!-- <view class="desc-item">
								<text>备注：杨阳洋</text>
							</view> -->
							<view class="item-price">
								<text>合计：￥{{ item.order_amount }}</text>
							</view>
              <view class="item-btns">
                <text v-if="item.status === 10" class="btn-item" @click.stop="handleToPay(item)">去支付</text>
<!--                <text class="btn-item" v-else>查看详情</text>-->
              </view>
						</view>
					</view>
				</mescroll-uni>
			</view>
		</view>
	</view>
</template>

<script>
	import { request } from "@/utils/tool";
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				list: [],
				queryKey: "",
				tabList: [{
						name: '全部'
					}, {
						name: '待付款'
					},
					{
						name: '待收货'
					}
				],
				current: 0,
			}
		},
		methods: {
      handleToPay(rowItem){
        console.log(rowItem,'rowItem')
      },
      handleToDetail(rowItem){
        uni.navigateTo({
          url:"/pages/index/order-manage/order-detail?id=" + rowItem.id
        })
      },
			handleSearch() {
				this.mescroll.triggerDownScroll()
			},
			async upCallback(ev) {
				const { num, size } = ev
				const { queryKey: keyword } = this
				const resp = await request({
					url: "/beihuotihuoorder/lists",
					method: "GET",
					data: {
						page_no: num,
						page_size: size,
						keyword
					}
				})
				const { lists, count } = resp.data
				if (num === 1) this.list = []
				this.list.push(...lists)
				this.mescroll.endBySize(lists.length, count)
			},
			handleTabChange(ev) {
				this.current = ev
				this.handleSearch()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.order-manage {
		.record-list {
			padding: 24rpx 20rpx 0;
			box-sizing: border-box;
			position: relative;

			.record-item {
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				padding-bottom: 22rpx;
				margin-bottom: 16rpx;
        .item-btns {
          margin-top: 16rpx;
          display: flex;
          align-items: center;
          justify-content: flex-end;

          .btn-item {
            padding: 6rpx 24rpx;
            background: #FFFFFF;
            border-radius: 200rpx 200rpx 200rpx 200rpx;
            border: 2rpx solid #3361F0;
            font-weight: bold;
            font-size: 26rpx;
            color: #3361F0;
            line-height: 40rpx;
            margin-left: 20rpx;
          }
        }
				&:last-child {
					margin-bottom: 0;
				}

				.item-price {
					margin-top: 4rpx;
					font-size: 26rpx;
					color: #515151;
					line-height: 44rpx;
					text-align: right;
					padding: 0 32rpx;
				}

				.desc-item {
					padding: 0 32rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #515151;
					line-height: 44rpx;
					white-space: pre-wrap;
					word-break: break-all;

					&.active {
						display: flex;
						align-items: center;
						justify-content: space-between;
					}
				}

				.order-type {
					padding: 0 32rpx;
					font-size: 24rpx;
					color: #3BB54E;
					line-height: 44rpx;
					padding-bottom: 12rpx;
					border-bottom: 2rpx solid #F3F3F3;
					margin-bottom: 8rpx;
				}

				.record-header {
					padding: 18rpx 32rpx 10rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.order-status {
						font-weight: bold;
						font-size: 28rpx;
						color: #515151;
						line-height: 44rpx;
					}

					.order-no {
						font-size: 28rpx;
						color: #515151;
						line-height: 44rpx;
					}
				}
			}
		}

		.tab-wrap {
			border-bottom: 2rpx solid #E7E7E7;
		}

		.header-wrap {
			padding: 10rpx 22rpx 16rpx 40rpx;
			display: flex;
			align-items: center;
			background: #fff;

			.filter-wrapper {
				display: flex;
				align-items: center;
				position: relative;
				border-left: 2rpx solid #818181;
				margin-left: 14rpx;
				padding-left: 8rpx;
				box-sizing: border-box;

				.filter-text {
					font-size: 26rpx;
					color: #818181;
					line-height: 44rpx;
					margin-left: 2rpx;
					white-space: nowrap;
				}

				.filter-icon {
					width: 28rpx;
					height: 28rpx;
				}
			}


			.search-btn {
				width: 116rpx;
				height: 62rpx;
				line-height: 62rpx;
				text-align: center;
				color: #fff;

				background: #3361F0;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				margin-left: 12rpx;
			}

			.header-search {
				display: flex;
				align-items: center;
				padding: 8rpx 18rpx;
				background: #F4F4F4;
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				width: 446rpx;

				.search-input {
					margin-left: 8rpx;
					font-size: 28rpx;
					height: 44rpx;
				}
			}
		}
	}
</style>